package com.fypg.module.medical.controller.app.auth;

import cn.hutool.core.util.StrUtil;
import com.fypg.framework.common.enums.UserTypeEnum;
import com.fypg.framework.common.pojo.CommonResult;
import com.fypg.framework.security.config.SecurityProperties;
import com.fypg.framework.security.core.util.SecurityFrameworkUtils;
import com.fypg.module.medical.controller.app.auth.vo.AppAuthLoginReqVO;
import com.fypg.module.medical.controller.app.auth.vo.AppAuthLoginRespVO;
import com.fypg.module.medical.controller.app.auth.vo.AppAuthWeixinMiniAppLoginReqVO;
import com.fypg.module.medical.service.auth.MemberAuthService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import static com.fypg.framework.common.pojo.CommonResult.success;
import static com.fypg.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;

@Tag(name = "用户 APP - 认证")
@RestController
@RequestMapping("/auth")
@Validated
@Slf4j
public class AppAuthController {

    @Resource
    private MemberAuthService authService;


    @Resource
    private SecurityProperties securityProperties;

    @PostMapping("/refresh-token")
    @Operation(summary = "刷新令牌")
    @Parameter(name = "refreshToken", description = "刷新令牌", required = true)
    @PermitAll
    public CommonResult<AppAuthLoginRespVO> refreshToken(@RequestParam("refreshToken") String refreshToken) {
        return success(authService.refreshToken(refreshToken));
    }

    @PostMapping("/weixin-mini-app-login")
    @Operation(summary = "微信小程序的一键登录")
    @PermitAll
    public CommonResult<AppAuthLoginRespVO> weixinMiniAppLogin(@RequestBody @Valid AppAuthWeixinMiniAppLoginReqVO reqVO) {
        return success(authService.weixinMiniAppLogin(reqVO));
    }

}
